package com.shiro.demo.service.impl;


import com.shiro.demo.domain.User;
import com.shiro.demo.mapper.UserMapper;
import com.shiro.demo.service.UserService;
import com.shiro.demo.utils.MD5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;
    @Override
    public User getUserByName(String name) {
        return this.userMapper.getUserByName(name);
    }

    @Override
    public User getUserByNameAndPassword(String name, String password) {
        return this.userMapper.getUserByNameAndPassword(name,password);
    }

    @Override
    public User getUserById(Long id) {
        return this.userMapper.getUserById(id);
    }

    @Override
    public void insertUser(User user) {
        String salt = MD5Util.getSalt();
        user.setPassword(MD5Util.getMD5CodeBySalt(user.getPassword(),salt));
        this.userMapper.insertUser(user);
    }

    @Override
    public void updateUser(User user) {
        this.userMapper.updateUser(user);
    }

    @Override
    public void deleteUser(Long id) {
        this.userMapper.deleteUser(id);
    }
}
